package com.hdy.orderforthree.mvp;

import com.hdy.net.order.NetCallback;
import com.hdy.net.order.bean.BasicDataResponse;

public class BillPresenter implements IBillContract.IPresenter{

    private BillView mBillView;
    private BillModel mBillModel;

    public BillPresenter(BillView billView, BillModel billModel) {
        mBillView = billView;
        mBillModel = billModel;
    }

    public void setUpdateViewCallback(TitleBarPresenter.UpdateViewCallback cb) {
        mBillView.setUpdateViewCallback(cb);
    }


    @Override
    public void detachView() {
        this.mBillView = null;
    }

    @Override
    public boolean isViewAttached() {
        return mBillView != null;
    }

    @Override
    public void loadBillData() {
        mBillView.showBill();

        NetCallback callback = new NetCallback<BasicDataResponse>(){
            @Override
            public void onError(Throwable e) {
                mBillModel.getBillData(this);
            }

            @Override
            public void onStart() {
            }

            @Override
            public void onCompleted() {
            }

            @Override
            public void onNext(BasicDataResponse basicDataResponse) {
                //处理已下单的返回数据
                mBillView.showBill();
            }
        };
        mBillModel.getBillData(callback);

        mBillView.showMoney();
    }

    public void notifyDataSetChanged() {
        mBillView.notifyDataSetChanged();
    }
}
